package com.miaomiao.controller.system;

import com.miaomiao.common.Result;
import com.miaomiao.domain.system.LoginBody;
import com.miaomiao.service.system.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "用户登入")
public class LoginController {

    @Autowired
    private LoginService loginService;

    /**
     * 登入
     * @param loginBody
     * @return
     */
    @PostMapping("/user/login")
    @ApiOperation("用户登入")
    public Result login(@RequestBody LoginBody loginBody) throws Exception {
        return loginService.login(loginBody);
    }

    /**
     * 登出
     * @return
     */

    @GetMapping("/user/logout")
    @ApiOperation("用户登出")
    public Result logout(){
        return loginService.logout();
    }

    /**
     * 获取登录验证码
     * @return
     */
    @GetMapping("/code")
    @ApiOperation("获取登录验证码")
    public Result getCode(){
        return loginService.getCode();
    }

    @GetMapping("/checkToken")
    @ApiOperation("检查token")
    public Result checkToken(){
        return Result.success("token有效");
    }
}
